// // 二元运算:
// 1 + 2
const testExpression01 = () => {
    const ast = [
        Plus(
            Num(1),
            Num(2),
        )
    ]
    const expect = 3
    const output = interpret(ast)
    ensure(expect === output, 'testExpression01')
}
// 1 * (2 + 3)
const testExpression02 = () => {
    const ast = [
        Multiply(
            Num(1),
            Plus(
                Num(2),
                Num(3),
            ),
        )
    ]
    const expect = 5
    const output = interpret(ast)
    ensure(expect === output, 'testExpression02')
}
// (2 - 3) + (2 * 3)
const testExpression03 = () => {
    const ast = [
        Plus(
            Minus(
                Num(2),
                Num(3)
            ),
            Multiply(
                Num(2),
                Num(3),
            ),
        )
    ]
    const expect = 5
    const output = interpret(ast)
    ensure(expect === output, 'testExpression03')
}
// 2 > 1


const testExpression04 = () => {
    const ast = [
        Greater(
            Num(2),
            Num(1),
        )
    ]
    const expect = true
    const output = interpret(ast)
    ensure(expect === output, 'testExpression04')
}
//
// // 普通变量声明:
// var a = 1
const testDeclaration01 = () => {
    const ast = [
        Declaration(
            Var('a'),
            Num(1),
        )
    ]
    interpret(ast)
    const expect = 1
    const output = valueOf('a')
    ensure(expect === output, 'testDeclaration01')
}

//
// // 变量声明:
// var a = 3 + 5
const testDeclaration02 = () => {
    const ast = [
        Declaration(
            Var('a'),
            Plus(
                Num(3),
                Num(5),
            ),
        )
    ]
    interpret(ast)
    const expect = 8
    const output = valueOf('a')
    ensure(expect === output, 'testDeclaration02')
}
// var a = 1
// var b = a + 1

const testDeclaration03 = () => {
    const ast = [
        Declaration(
            Var('a'),
            Num(1),
        ),
        Declaration(
            Var('b'),
            Plus(
                Var('a'),
                Num(1),
            ),
        ),
    ]
    interpret(ast)
    const expect = 2
    const output = valueOf('b')
    ensure(expect === output, 'testDeclaration03')
}
// var a = 1
// var b = 1
// var c = a + b
const testDeclaration04 = () => {
    const ast = [
        Declaration(
            Var('a'),
            Num(1),
        ),
        Declaration(
            Var('b'),
            Num(1),
        ),
        Declaration(
            Var('c'),
            Plus(
                Var('a'),
                Var('b'),
            ),
        ),
    ]
    interpret(ast)
    const expect = 2
    const output = valueOf('c')
    ensure(expect === output, 'testDeclaration04')
}
// var c = 2
// var d = c
const testDeclaration05 = () => {
    const ast = [
        Declaration(
            Var('c'),
            Num(2),
        ),
        Declaration(
            Var('d'),
            Var('c'),
        ),
    ]
    interpret(ast)
    const expect = 2
    const output = valueOf('d')
    ensure(expect === output, 'testDeclaration05')
}

//
// // if 语句:
// if (true) {
//     1 + 2
// }
const testIf01 = () => {
    const ast = [
        If(
            True(),
            Block([
                Plus(
                    Num(1),
                    Num(2),
                )
            ]),
        ),
    ]
    const expect = interpret(ast)
    const output = 3
    ensure(expect === output, 'testIf01')
}


// // if-else语句:
// if (false) {
//     1 + 2
// } else {
//     3 + 4
// }

const testIf02 = () => {
    const ast = [
        If(
            False(),
            Block([
                Plus(
                    Num(1),
                    Num(2),
                )
            ]),
            Block([
                Plus(
                    Num(3),
                    Num(4),
                )
            ])
        ),
    ]
    const expect = interpret(ast)
    const output = 7
    ensure(expect === output, 'testIf02')
}
//
// // if-else 二元运算
// var a = 3
// if (a > 0) {
//     1 + 2
// } else {
//     3 + 4
// }

const testIf03 = () => {
    const ast = [
        Declaration(
            Var('a'),
            Num(3),
        ),
        If(
            Greater(
                Var('a'),
                Num(0),
            ),
            Block([
                Plus(
                    Num(1),
                    Num(2),
                )
            ]),
            Block([
                Plus(
                    Num(3),
                    Num(4),
                )
            ])
        ),
    ]
    const expect = interpret(ast)
    const output = 3
    ensure(expect === output, 'testIf03')
}




const _main = () => {
    testExpression01()
    testExpression02()
    testExpression03()
    testExpression04()


}

_main()